package com.mindata.blockchain.core.sqlparser;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.mindata.blockchain.block.Operation;
import com.mindata.blockchain.common.CommonUtil;
import com.mindata.blockchain.core.model.OrderEntity;
import com.mindata.blockchain.core.model.PayEntity;
import com.mindata.blockchain.core.model.TicketEntity;
import com.mindata.blockchain.core.repository.OrderRepository;
import com.mindata.blockchain.core.repository.PayRepository;
import com.mindata.blockchain.core.repository.TicketRepository;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author 王鹏
 */
@Service
public class PaySqlParser extends AbstractSqlParser<PayEntity>{

    @Resource
    private PayRepository payRepository;

    @Resource
    private OrderRepository orderRepository;

    @Resource
    private TicketRepository ticketRepository;

    @Override
    void parse(byte operation, String id, PayEntity entity) {
        if (Operation.ADD == operation) {
            // 支付成功
            entity.setCreateTime(CommonUtil.getNow());
            entity.setPayId(id);
            payRepository.save(entity);
        }
    }

    @Override
    Class getEntityClass() {
        return PayEntity.class;
    }
}
